unit io_ImageCapture_Windows_output;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, io_ImageCapture_output, Controls, windows;

type
  { TIOOutput }

  { TIO_ImageCapture_Windows_Output }

  TIO_ImageCapture_Windows_Output = class(TIO_ImageCapture_Output)
    private
      FWindowHandle: HWND;
    public
      constructor Create;
      destructor Destroy; override;
    protected
      procedure KeyEvent(APressed: boolean; AKey: Word); override;
      procedure MouseMove(Ax,Ay: Integer); override;
      procedure MouseEvent(APressed: boolean; Ax, Ay: Integer); override;
    public
      property WindowHandle: HWND read FWindowHandle write FWindowHandle;
  end;

implementation

{ TIO_ImageCapture_Windows_Output }

constructor TIO_ImageCapture_Windows_Output.Create;
begin
  inherited;
end;

destructor TIO_ImageCapture_Windows_Output.Destroy;
begin
  inherited Destroy;
end;

procedure TIO_ImageCapture_Windows_Output.KeyEvent(APressed: boolean; AKey: Word);
begin
  if APressed then
  begin
    SendMessage(WindowHandle,WM_KEYDOWN,AKey, %00000000000000000000000000000000);
  end;

  if not APressed then
  begin
    SendMessage(WindowHandle,WM_KEYUP  ,AKey, %00000000000000010000000000000011);
  end;
end;

procedure TIO_ImageCapture_Windows_Output.MouseMove(Ax, Ay: Integer);
begin
  SendMessage(WindowHandle,WM_MOUSEMOVE,0,MAKELONG(Ax,Ay));
end;

procedure TIO_ImageCapture_Windows_Output.MouseEvent(APressed: boolean; Ax, Ay: Integer);
begin
  SetCursorPos(ax,ay);
  if APressed then
  begin
    mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
  end else
  begin
    mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
  end;
end;

end.

